#include<stdio.h>
#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
int value = 0;
int fork_ques(){
	pid_t pid;

	pid = fork();
	
	if (pid == 0) { /* child process */
		value += 15;
	}
	else if (pid > 0) { /* parent process */
		wait(NULL);
		printf ("PARENT: value = %d\n",value); /* LINE A */
	}else return -1;
    return 0;
}
void fork_test(){
    printf("%d\n",getpid());
	fork();
	printf("%d\n",getpid());
	

	fork();
	printf("%d\n",getpid());

	fork();
	printf("%d\n",getpid());
}
void process_count(){
    // fork();
    fork() && fork() || fork();
    // fork();
    printf("parent : %d\tself : %d\n",getppid(),getpid());
}
bool falseAdd(){
    ++value;puts("false");
    return false;
}
bool trueAdd(){
    ++value;puts("true");
    return true;
}
void exec_0(){
    int childpid;  
    int i;
    if (fork() == 0){  
        //child process  
        char * execv_str[] = {"echo", "executed by execv",NULL};  
        if (execv("/usr/bin/echo",execv_str) <0 ){  
            perror("error on exec");  
            exit(0);  
        }  
    }else{  
        //parent process  
        wait(&childpid);  
        printf("execv done\n\n");  
    }  
}
void exec_1(){
    char * execv_str[] = {"echo", "executed by execv",NULL};
    execv("/bin/echo",execv_str);
    puts("error");
}
void execl_0(){
    int childpid;  
    int i;
    if (fork() == 0){  
    //child process  
        if (execl("/bin/echo","echo","execl" ,NULL) <0 ){  
            perror("error on exec");  
            exit(0);  
        } 
    }else{  
        //parent process  
        wait(&childpid);  
        printf("execl done\n\n");  
    }  

}
int main(){
    execl_0();
    // process_count();
    // wait(NULL);
    // falseAdd()&&trueAdd()||falseAdd();
    // (0&&0)||1;// true
    // 0&&(0||1);// false
    // std::cout<<(0&&0||1);
    return 0;
}
